﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using ClassLibrary1;
using Domain.Entities;

namespace Webservice.Controllers
{
    [Authorize]
    public class ValuesController : ApiController
    {
        // GET api/values
        [AllowAnonymous]
        public IEnumerable<string> Get()
        {
            using (var db = new MyHealthDbContext())
            {
                var billStatus = new BillStatus {Name = "Outstanding"};
                db.BillStatus.Add(billStatus);
                var healthCareEntityType = new HealthCareEntityType {Name = "GP"};
                db.HealthCareEntityTypes.Add(healthCareEntityType);
                var orderLine = new OrderLine
                {
                    Amount = 2000,
                    Code = "cxe100",
                    Date = DateTime.Now,
                    Description = "testOrderLine"
                };
                db.OrderLines.Add(orderLine);
                var mhUser = new MhUser
                {
                    Address = "here", 
                    Email = "abc@def.ghi", 
                    FirstName = "Awesome T.",
                    LastName = "Man",
                    InsuranceNumber = "VGZ101",
                    Username = "test",
                    Password = "test"
                };
                db.Users.Add(mhUser);
                var healthCareEntity = new HealthCareEntity
                {
                    Address = "There",
                    Email = "abc@def.ghi",
                    Name = "Dokter wie",
                    Username = "test1",
                    Password = "test1",
                    Type = healthCareEntityType
                };
                db.HealthCareEntities.Add(healthCareEntity);
                var bill = new Bill
                {
                    OwedBy = mhUser, 
                    OwedTo = healthCareEntity, 
                    Status = billStatus
                };
                db.Bills.Add(bill);


                const string hello = "hey";
                var example = new Example {Hello = hello};
                db.Examples.Add(example);
                db.SaveChanges();

                // Display all Examples from the database 
                var query = from e in db.Examples
                    orderby e.Hello
                    select e;
                var results = new List<string>();
                Console.WriteLine("All blogs in the database:");
                foreach (var exmpl in query)
                {
                    results.Add(exmpl.Hello);
                    Console.WriteLine(exmpl.Hello);
                }

                Console.WriteLine("Press any key to exit...");
                return results;
            }

        }

        // GET api/values/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/values
        public void Post([FromBody]string value)
        {
        }

        // PUT api/values/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
        }
    }
}
